package com.kly.cashmall.utils.data;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

/**
 * @author zxp
 * @since 27/10/21
 */
public class ZipUtils {
    public ZipUtils() {
    }

    public static String gzip(String primStr) {
        if (primStr != null && primStr.length() != 0) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            GZIPOutputStream gzip = null;

            try {
                gzip = new GZIPOutputStream(out);
                gzip.write(primStr.getBytes());
            } catch (IOException var12) {
                var12.printStackTrace();
            } finally {
                if (gzip != null) {
                    try {
                        gzip.close();
                    } catch (IOException var11) {
                        var11.printStackTrace();
                    }
                }

            }

            return (new BASE64Encoder()).encode(out.toByteArray());
        } else {
            return primStr;
        }
    }
}
